package com.shawn.mobliesafe;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;


public class SetUp3Activity extends SetUpBaseActivity {

    private EditText et_setup3_safenum;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set_up3);
        et_setup3_safenum = (EditText)findViewById(R.id.et_setup3_safenum);
        et_setup3_safenum.setText(sp.getString("safenum",""));
    }

    @Override
    public void next_activity() {
        String safenum = et_setup3_safenum.getText().toString().trim();
        if(TextUtils.isEmpty(safenum)) {
            Toast.makeText(getApplicationContext(), "请输入安全号码", Toast.LENGTH_SHORT).show();
            return;
        }
        SharedPreferences.Editor editor = sp.edit();
        editor.putString("safenum",safenum);
        editor.commit();
        Log.e("TAG","set3-safenum:"+safenum);
        Intent intent = new Intent(this,SetUp4Activity.class);
        startActivity(intent);
        finish();
        overridePendingTransition(R.anim.setup_enter_next, R.anim.setup_exit_next);
    }

    @Override
    public void pre_activity() {
        Intent intent = new Intent(this,SetUp2Activity.class);
        startActivity(intent);
        finish();
        overridePendingTransition(R.anim.setup_enter_pre, R.anim.setup_exit_pre);
    }

    /**
     * 选择联系人按钮
     * @param view
     */
    public void selectContacts(View view){
        //跳转到选择联系人界面
        Intent intent = new Intent(this,ContactActivity.class);
        startActivityForResult(intent,0);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(data!=null) {
            if(requestCode == 0 && resultCode == RESULT_OK) {
                String number = data.getStringExtra("number");

                number = number.replaceAll("-", "");//替换的操作,555-6 -> 5556
                et_setup3_safenum.setText(number);
            }
        }
    }
}
